package com.dwxt.mall.service;

import com.dwxt.common.util.OkHttpUtils;
import com.dwxt.mall.constant.OrderStatus;
import com.dwxt.mall.entity.PayOrder;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TaskService {

    @Value("${dongMei.url}")
    private String dongMeiUrl;

    @Autowired
    private OrderService orderService;

    public void checkRefundOrder() {
        List<PayOrder> orderList = orderService.selectOrderByCategoryAndStatus("场馆预定", OrderStatus.REQUEST_REFUND);
        Map<String, String> headers = new HashMap<>();
        headers.put("username", "15123058497");
        headers.put("Signature", "2ddfeb530a2e81c9f45ed37398e6a20ec357d1c9");
        for (PayOrder order : orderList) {
            String url = dongMeiUrl + "order?OrderNumber=" + order.getNonceStr();
            JSONObject result = JSONObject.fromObject(OkHttpUtils.synGet(url, headers));
            if (result.getInt("errorcode") == 0) {
                int statusCode = result.getJSONObject("value").getInt("StatusCode");
                //修改订单状态
            }
        }
    }
}
